package com.sample.servicemanager
{
	
	import com.sample.constants.MessageConstants;
	import com.sample.vos.Globals;
	
	import flash.events.EventDispatcher;
	
	import org.ticlib.events.LoadingEvent;
	import org.ticlib.events.NotificationEvent;
	
	[Event(name="loadingBegin", type="org.ticlib.events.LoadingEvent")]
	[Event(name="loadingEnd", type="org.ticlib.events.LoadingEvent")]
	[Event(name="notificationShow", type="org.ticlib.events.NotificationEvent")]
	[ManagedEvents("loadingBegin, loadingEnd, notificationShow")]
	public class ManagerBase extends EventDispatcher
	{
		[Injeczt]
		[Bindable] public var globals:Globals;
		[Bindable] public var isLoading:Boolean;
		
		public function ManagerBase()
		{
			isLoading = false;
		}
		
		protected function showLoadingMask():void
		{
			isLoading = true;
			dispatchEvent(new LoadingEvent(LoadingEvent.BEGIN));
		}
		
		protected function hideLoadingMask():void
		{
			isLoading = false;
			dispatchEvent(new LoadingEvent(LoadingEvent.END));
		}
		
		protected virtual function taskFault():void
		{
			hideLoadingMask();
			dispatchEvent(NotificationEvent.error(MessageConstants.FAULT_CONNECT));
		}
		
		protected virtual function taskCanceled():void
		{
			hideLoadingMask();
			dispatchEvent(NotificationEvent.info(MessageConstants.STOP_CONNECT));
		}
	}
}